<!-- 时间选择器 -->
<template>
    <div>
        <el-config-provider :locale="zhCn">
            <el-date-picker v-model="value" :disabled-date="disabledDate" type="month" placeholder="选择日期" format="YYYY/MM" value-format="YYYY-MM"
                 />
        </el-config-provider>
    </div>
</template>
   
<script lang="ts" setup>
import { defineEmits, watch,onMounted } from 'vue'
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { ref } from "vue";

const value = ref()
const props = defineProps({
  //子组件接收父组件传递过来的值
  value: String,
  limit:{
    type:String,
    default:''
  }
})
onMounted(()=>{
    value.value = props.value
})
const emit = defineEmits(['child'])
watch(value,(newValue,oldValue)=>{
  emit('child',newValue)
})
const disabledDate = (time: Date) => {
    if(props.limit==='') return false 
    else switch(props.limit){
        case "<":
        return time.getTime() > Date.now()
        case ">":
        return time.getTime() > Date.now()
    }
}

</script>